package com.ftg.learn.chapter15;

import com.ftg.learn.chapter15.proxy.dong.Isinger;
import com.ftg.learn.chapter15.proxy.dong.Singer;
import org.junit.Test;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author KangJx
 * @date 2021/8/2
 */
public class DongTest {

    @Test
    public void test1(){

        //目标类
        Singer s = new Singer();

        Isinger isingerProxy = (Isinger) Proxy.newProxyInstance(Singer.class.getClassLoader(),
                Singer.class.getInterfaces(), new InvocationHandler() {
                    //想在目标类不变的情况下，进行相应方法扩容，前  后  周围

                    //method切点
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        //小丁.....(织入)
                        System.out.println("===>");
                       Object o = method.invoke(s,args);
                       //小澎ret
                       return o;
                    }
                });
        isingerProxy.singsong();

    }

}
